<template>
  <el-menu
    :default-active="activeMenu"
    style="width: 150px"
    @select="select"
    @open="handleOpen"
    :unique-opened="true"
    class="el-menu-vertical-demo"
  >
    <el-submenu :index="item.code" v-for="(item, index) in productListArr" :key="index">
      <template slot="title">
        <span :title="item.name + '('+ item.countNum + ')'"><span class="one-level">{{item.name}}</span>({{item.countNum}})</span>
      </template>
      <el-menu-item :index="v.code" v-for="v in item.childLists" :key="v.code">
        <span :title="v.name + '('+ v.countNum + ')'">{{v.name}}({{v.countNum}})</span>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
// import {dotData} from 'assets/scripts/base/functions'
import {bus} from '@/utils/bus'

export default {
  name: 'productMenuModal',
  components: {},
  data() {
    return {
      productListArr: [],
      activeMenu: '',
      checkData: {
        bigClassCode: '',
        minddleClassCode: ''
      }
    }
  },
  created() {
    bus.$on('activeSubmenuValFHB', (classCode) => {
      console.log('classCode1', classCode)
      this.activeMenu = classCode
      this.getBigClass()
    })
    this.getBigClass()
  },
  methods: {
    select(val) {
      this.activeMenu = val
      this.checkData.minddleClassCode = val
      bus.$emit('activeMenuValFHB', this.checkData)
    },
    handleOpen(val, keyPath) {
      this.checkData.bigClassCode = val
    },
    getBigClass() {
      // 1：商家下单 ,2:商家添加，3:后台添加
      this.$ajax.get('/ms-fahuobao-order/FhbOrder/getGoodNums', {state: '2'}).then(response => {
        if (!response.success) {
          return
        }
        this.productListArr = response.data
      })
    },
    beforeDestroy() {
      bus.$off('activeSubmenuValFHB')
    }
  }
}
</script>
